﻿

using Main.Extend.Attributes;
using Microsoft.Extensions.Configuration;
using System.Text;

namespace Main.Common
{
    /// <summary>
    /// 随机数帮助类
    /// </summary>
    [Provider, Inject]
    public class RandomHelper : BaseCommon
    {
        public RandomHelper(IConfiguration configuration) : base(configuration)
        {
        }

        /// <summary>
        /// 生成一个 随机位数的 0-9 的随机码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public string Next(int length = 6)
        {
            Random R = new Random();
            StringBuilder Builder = new StringBuilder();
            for (int i = 1; i <= length; i++)
            {
                Builder.Append(R.Next(0, 9) + 1);
            }
            return Builder.ToString();
        }
        /// <summary>
        /// 生成一个范围内的随机数
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public int RangeNumber(int start, int end)
        {
            Random R = new Random();
            return R.Next(start, end) + 1;
        }
    }
}
